﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Handlers
{
    using FiftyOne.Foundation.Mobile.Detection.Wurfl;
    using System;

    internal class AppleHandler : RegexSegmentHandler
    {
        private const int CONFIDENCE = 6;
        private const string DEFAULT_DEVICE = "apple_iphone_ver1";
        private static readonly string[] PATTERNS = new string[] { "iPhone|iPod|iPad", @"(?<=AppleWebKit/)[\d.]+", @"(?<=Version/)[\d.]+", @"(?<=Mobile/)[\d\w]+", @"(?<=Safari/)[\d.]+" };

        public AppleHandler() : base(PATTERNS, new int[] { 100, 1, 1, 1, 1 })
        {
        }

        protected internal override bool CanHandle(string userAgent)
        {
            return ((userAgent.Contains("iPhone") || userAgent.Contains("iPod")) || userAgent.Contains("iPad"));
        }

        internal override byte Confidence
        {
            get
            {
                return 6;
            }
        }

        internal override DeviceInfo DefaultDevice
        {
            get
            {
                DeviceInfo deviceInfoFromID = Provider.Instance.GetDeviceInfoFromID("apple_iphone_ver1");
                if (deviceInfoFromID != null)
                {
                    return deviceInfoFromID;
                }
                return base.DefaultDevice;
            }
        }
    }
}

